/*
*    Phantom v2.0 GUI Automation Software
*    Copyright (C) 2009  John C. Van Arsdall (john@phantomtest.com)
*
*    This program is free software; you can redistribute it and/or modify
*    it under the terms of the GNU General Public License as published by
*    the Free Software Foundation; either version 2 of the License, or
*    (at your option) any later version.
*
*    This program is distributed in the hope that it will be useful,
*    but WITHOUT ANY WARRANTY; without even the implied warranty of
*    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
*    GNU General Public License for more details.
*
*    You should have received a copy of the GNU General Public License along
*    with this program; if not, write to the Free Software Foundation, Inc.,
*    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
*/
// Data.h: interface for the CData class.
//
//////////////////////////////////////////////////////////////////////

#if !defined(AFX_DATA_H__EE8AA2D8_3FD7_415E_B588_4A2AAFD3A591__INCLUDED_)
#define AFX_DATA_H__EE8AA2D8_3FD7_415E_B588_4A2AAFD3A591__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#include "ssi_includes.h"
#include "ssi_string.h"
#include "ssi_status.h"
#include "ssi_stream.h"

// Evidently this is needed here
#include "ssi_variable.h"

class CEngine;
class CStatement;
//class CVariable;
class CFunctionSet;
class SSI_FunctionAPI;
//typedef TNodeTree<CVariable> VarTree;
//typedef TNode<CVariable> VarNode;

typedef struct{
	SSI_INT64 Size;
	CEngine* anEngine;
	String* sInfo;
}OpInfoT;

class CStatus;
class CVariable;
class CDataFactory;
class CFunctionDecl;
class CInterpreter;

class SSI_SCRIPTDLL_API CData  
{
	friend class CDataFactory;
public:
	static CData* NewData(SSI_INT64 Type);
  virtual SSI_BOOL boolean();
	SSI_INT64 Type;
	String DataName;

	CData();
	virtual ~CData();
  virtual CData& operator=(CData& Other);
  operator int();

public:
	SSI_INT64 GetType(void);

	virtual CData* operator_plus(CData* InData, OpInfoT* Info = SSI_NULL);
	virtual CData* operator_equal(CData* InData, OpInfoT* Info = SSI_NULL);
	virtual CData* operator_minus(CData* InData, OpInfoT* Info = SSI_NULL);
	virtual CData* operator_multiply(CData* InData, OpInfoT* Info = SSI_NULL);
  virtual CData* operator_modulous(CData* InData, OpInfoT* Info = SSI_NULL);
	virtual CData* operator_divide(CData* InData, OpInfoT* Info = SSI_NULL);
	virtual CData* operator_power(CData* InData, OpInfoT* Info = SSI_NULL);
  virtual CData* operator_bit_and(CData* InData, OpInfoT* Info = SSI_NULL);
  virtual CData* operator_bit_or(CData* InData, OpInfoT* Info = SSI_NULL);

	virtual CStatus negate(void);

	// Deprecated
	//virtual CStatus EvalClass(VarItor InVars, VarTree& InTree, CStatement& aStat);

// Pure Virtual Functions:
private:
	virtual SSI_BOOL CopyData(CData* Other) = 0;
	virtual CData* MakeData(void) = 0;
public:
	virtual SSI_BOOL DeleteData(CData* In);  // Not pure yet, but still must be made pure
	virtual SSI_BOOL DataFromString(const String& sData) = 0;
	virtual String GetString() = 0;
  virtual SSI_INT64 SizeOf() = 0;
	virtual SSI_INT64 Register(SSI_INT64 NewType) = 0;
	virtual void UnRegister() = 0;

	CFunctionSet* FuncSet;
	VarTree* VarSet;

	virtual CStatus InitData(void);
private:
	CData* MakeData_Internal(void);
public:
	virtual CStatus AddFunction(CFunctionDecl& NewFunc);
	virtual CStatus EvalFunction(VarItor TopVar, VarTree& InTree, CStatement& aStat);
	virtual void SSI_FunctionProcessor(SSI_FunctionAPI& theAPI);
	virtual CStatus AddVariable(CVariable& newVar);
	SSI_BOOL GetVariable(CVariable& Var, CInterpreter* anInterp = 0);
	CStatus SetVariable(CVariable& aVar);
	virtual CStatus SSI_UpdateVariable(CVariable& aVar, SSI_BOOL bGet);
	CData* operator_equal_internal(CData* InData, OpInfoT* Info);
	CStatus AddVariable(CData* InData, String& Name);
	virtual SSI_BOOL IsFunction(const String& fName);
	virtual CStatus operator_compare(CData* InData, SSI_INT64& Result);
	virtual CStatus operator_decrement();
	virtual CStatus operator_increment();
	virtual void DisplayMembers(ssi_stream* out);
	virtual void DisplayMembersHELP(String& FileName);
  virtual String GetMemberFunctions(const String& Delim);
	virtual CStatus AddLocalVariable(CData* InData, String& Name);
};

#include "ssi_datafactory.h"

#endif // !defined(AFX_DATA_H__EE8AA2D8_3FD7_415E_B588_4A2AAFD3A591__INCLUDED_)

/* RULES FOR CREATING A NEW DATA
Create the Data Member
Initialize in the Constructor
Override DataFromString
Override GetString
Override CopyData
Override SizeOf
Override MakeData
Override DeleteData  --> Is this really necessary?

Optional----
Override operators
Override boolean
Override InitData
Override SSI_FunctionProcessor
Override SSI_UpdateVariable

In Constructor:
Register the DataType and Set the Type.
Set the String DataName
Track if registered (by adding a static, maybe)

In the .cpp file, create a global var to force registration for now


*/




